package com.qifan.alb2b.dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.stereotype.Repository;

import com.cqcis.base.orm.jdbc.JdbcUtil;
import com.qifan.alb2b.domain.TravelItemInfoDomain;

@Repository
public class TravelItemInfoDao extends BaseDao{

	public void add(TravelItemInfoDomain travelItemInfo){
		super.addObj(travelItemInfo);
	}
	
	/**
	 * 批量增加
	 * @param list
	 */
	public void add(List<TravelItemInfoDomain> list){
		final List<TravelItemInfoDomain> tempList=list;
		String sql="insert into TRAVELITEMINFO(ITEMID,TRAVELID,RESOURCETYPE,RESOURCEID,ISSTD,PRICE,REMARK) values(?,?,?,?,?,?,?)";
		this.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
			
			public void setValues(PreparedStatement ps, int i) throws SQLException {
				ps.setString(1, tempList.get(i).getItemId());
				ps.setString(2, tempList.get(i).getTravelId());
				ps.setInt(3, tempList.get(i).getResourceType());
				ps.setString(4, tempList.get(i).getResourceId());
				ps.setInt(5, tempList.get(i).getIsStd());
				ps.setDouble(6, tempList.get(i).getPrice());
				ps.setString(7, tempList.get(i).getRemark());
			}
			
			public int getBatchSize() {				
				return tempList.size();
			}
		});
	}
	
	
	public List<TravelItemInfoDomain> query(String travelId){
		String sql="select * from travelItemInfo where travelId=?";
		return JdbcUtil.queryForList(this, TravelItemInfoDomain.class, sql, travelId);
	}
	
}
